// const authorize = require('../openApi/authorize/authorize.js').authorize;
// const feedback = require('../interface/feedback/feedback.js');
const config = require('../../../bubaocloud/config.js');
const fileType = require('../../../utils/fileType.js').getType;

function getFileTypeSrc(fileName) {
  let fileTypes = fileType(fileName);
  return {
    src: `${config.host.rest}image/type/${fileTypes.typeName}.png`,
    typeName: fileTypes.typeName,
    typeNum: fileTypes.typeNum,
    type: fileTypes.type
  };
};

const video = {
  chooseVideo(data={}) {
    return new Promise((resolve, reject) => {
      wx.chooseVideo({
        sourceType: data.sourceType ? data.sourceType : ['album', 'camera']	,
        maxDuration: data.maxDuration ? data.maxDuration : 60,
        compressed: data.compressed ? data.compressed:true,
        camera: data.camera ? data.camera :'back',
        success: function (res) {
          res.path = res.tempFilePath;
          res.tempFilePath = res.thumbTempFilePath;
          let fileInfo = getFileTypeSrc(res.path);
          res.fileName = `${new Date().getTime()}.${fileInfo.type}`;
          res.typeSrc = fileInfo.src;
          res.fileInfo = fileInfo; 
          resolve(res) },
        fail: function (res) {
          reject(res) },
        complete: function (res) {
         },
      })
    })
  }
}

module.exports=video